package com.kye.express.business.jd.after_sale;

import com.kye.express.contract.base.BasePresenter;
import com.kye.express.contract.base.view.IView;
import com.kye.model.UserSession;
import com.kye.model.base.RetrofitManager;
import com.kye.model.bean.user.User;
import com.kye.model.service.JDService;

import io.reactivex.functions.Consumer;

/**
 * @author : Joe
 * @version : 1.0
 * @editor : Joe
 * @created : 18/12/2017
 * @updated : 18/12/2017
 * @description : <Description>
 * @update_reason : <UpdateReason>
 */

public interface JDAfterSaleMainConstract {

    interface JDAfterSaleMainView extends IView {

        void onUser(User user);

        void onLoading();

        void onLoaded();
    }

    class JDAfterSaleMainPresenter extends BasePresenter<JDAfterSaleMainView> {

        private JDService jdService;

        public JDAfterSaleMainPresenter() {
            jdService = RetrofitManager.getInstance().createOpenApiService(JDService.class);
        }

        @Override
        public void bind(JDAfterSaleMainView view) {
            super.bind(view);
            UserSession.getInstance()
                    .getUserForRx()
                    .compose(getView().bindToLifecycleDestroy())
                    .subscribe(new Consumer<User>() {
                        @Override
                        public void accept(User user) throws Exception {
                            getView().onUser(user);
                        }
                    });
        }
    }
}
